import { reqCategoryList, bannerList, reqfloorList } from '@/api'

// 仓库储存数据的地方
const state = {
  cateGoryList: [],
  bannerList: [],
  floorList: []
}
// 修改state的唯一手段
const mutations = {
  CATEGORYLIST(state, cateGoryList) {
    state.cateGoryList = cateGoryList
  },
  // 轮播图
  BANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  FLOORLIST(state, floorList) {
    state.floorList = floorList
  }
}
// 处理action 可以书写业务逻辑 也可以处理异步
const actions = {
  async cateGoryList({ commit }) {
    const res = await reqCategoryList()
    if (res.code == 200) {
      commit('CATEGORYLIST', res.data)
    }
  },
  // 获取首页轮播图
  async getBannerList({ commit }) {
    const res = await bannerList()
    if (res.code === 200) {
      commit('BANNERLIST', res.data)
    }
  },
  // 获取floor数据
  async getFloorList({ commit }) {
    const res = await reqfloorList()
    if (res.code === 200) {
      commit('FLOORLIST', res.data)
    }
  }
}
const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}
